package com.holly.unit.gen.api.config;

import com.holly.unit.gen.api.constants.GenFileCfgConstants;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 类描述: 文件生成配置类
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/1/14 13:36
 */
public class GenFileCfg {

    // 模板文件路径
    private String templatePath;

    // 代码模板文件夹子目录
    private List<File> tmpRootDirs = new ArrayList<>();

    // 生成文件扩展路径
    private String customePath;

    public GenFileCfg(String _templatePath) {
        this.templatePath = _templatePath;
    }

    public String getTemplatePath() {
        return templatePath;
    }

    public void setTemplatePath(String templatePath) {
        this.templatePath = templatePath;
    }

    public List<File> getTmpRootDirs() {

        // 修改代码
        String clsPath = System.getProperty(GenFileCfgConstants.USER_DIR)
                +File.separator+GenFileCfgConstants.CODE_PATH.replace(GenFileCfgConstants.SPLITE,File.separator);

//        String clsPath = this.getClass().getResource(templatePath).getFile();
//        clsPath = clsPath.replaceAll(GenFileCfgConstants.SPACE,GenFileCfgConstants.BLANK);
//        if (clsPath.indexOf(GenFileCfgConstants.BOOT_INFO_CLASS) != -1) {
//            clsPath = System.getProperty(GenFileCfgConstants.USER_DIR)
//                    +File.separator+GenFileCfgConstants.CODE_PATH.replace(GenFileCfgConstants.SPLITE,File.separator);
//        }
        setTmpRootDirs(new File(clsPath));
        return tmpRootDirs;
    }

    public void setTmpRootDirs(List<File> tmpRootDirs) {
        this.tmpRootDirs = tmpRootDirs;
    }

    public void setTmpRootDirs(File file) {
        setTmpRootDirs(new File[]{file});
    }

    public void setTmpRootDirs(File... file) {
        this.tmpRootDirs = Arrays.asList(file);
    }

    public String getCustomePath() {
        return customePath;
    }

    public void setCustomePath(String customePath) {
        this.customePath = customePath;
    }
}
